package com.lzm.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzm.mapper.DepartmentsMapper;
import com.lzm.mapper.DoctorMapper;
import com.lzm.mapper.HosregisterMapper;
import com.lzm.pojo.Hosregister;
import com.lzm.pojo.HosregisterExample;
import org.springframework.stereotype.Service;
import com.lzm.vo.QueryVo;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class hosRegisterService {
    @Resource
    private HosregisterMapper hosregisterMapper;
    @Resource
    private DoctorMapper doctorMapper;
    @Resource
    private DepartmentsMapper departmentsMapper;
    @Transactional(propagation = Propagation.REQUIRED,readOnly = true)
    public PageInfo<Hosregister> queryByPage(Integer pageNum, Integer pageSize, QueryVo vo) {
        //分页
        PageHelper.startPage(pageNum, pageSize);
        List<Hosregister> list = hosregisterMapper.queryByVo(vo);
        for (Hosregister hosregister : list) {
            hosregister.setDoctor(doctorMapper.selectByPrimaryKey(hosregister.getDoctor_id()));
            hosregister.setDepartments(departmentsMapper.selectByPrimaryKey(hosregister.getHosR_keshi()));
            System.out.println(hosregister);
        }
        return new PageInfo<>(list);
    }
    public int addHosregister(Hosregister hosregister){
        return hosregisterMapper.insertSelective(hosregister);
    }

    public Hosregister queryById(Integer hosR_id){
        Hosregister hosregister = hosregisterMapper.selectByPrimaryKey(hosR_id);
        hosregister.setDoctor(doctorMapper.selectByPrimaryKey(hosregister.getDoctor_id()));
        hosregister.setDepartments(departmentsMapper.selectByPrimaryKey(hosregister.getHosR_keshi()));
        return hosregister;
    }
    public int updateHosRegister(Hosregister hosregister){
        return hosregisterMapper.updateByPrimaryKeySelective(hosregister);
    }

    public int deleteHosRegister(Integer hosR_id){
        Hosregister hosregister = hosregisterMapper.selectByPrimaryKey(hosR_id);
        hosregister.setHosR_state(3);
        return hosregisterMapper.updateByPrimaryKeySelective(hosregister);
    }
    public int deleteList(List<Integer> list){
        return hosregisterMapper.delList(list);
    }
}